/*********************************************************************************
 *      Copyright:  (C) 2025 LingYun<iot25@lingyun>
 *                  All rights reserved.
 *
 *       Filename:  daemon.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(16/03/25)
 *         Author:  LingYun <iot25@lingyun>
 *      ChangeLog:  1, Release initial version on "16/03/25 13:09:55"
 *                 
 ********************************************************************************/
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<errno.h>
#include<libgen.h>
#include<syslog.h>
int main(int argc, char  *argv[])
{
	char			*program = basename(argv[0]);

	if(daemon(0,0)<0)
	{
		printf("Program daemon() faliure:%s\n",strerror(errno));
		return -1;
	}

	openlog("daemon", LOG_CONS | LOG_PID,0);
	syslog(LOG_NOTICE,"Program '%s'start running\n", program);
	syslog(LOG_WARNING, "Program '%s' running with a warning message\n", program);
	syslog(LOG_EMERG, " Program '%s' running with a emergency message\n", program);

	while(1)
	{
		//Do something here
		;
	}
	syslog(LOG_NOTICE, " Program '%s' stop running\n",program);

	closelog;
	return 0;
}

